const http = require("http"); //网络请求模块
const urlModel = require("url"); //解析URL地址模块
const fs = require("fs"); //文件操作模块

//创建一个httpServer
let serve = http.createServer();
//监听"request"事件, 设置监听回调
    // req -> request请求
    // res -> response响应
serve.on("request", function (request, response) {
    let a = {
        a: 100,
        b: 200
    };



    //用urlModel.pares把请求url转换成对象形式
    let callbackObj = urlModel.parse(request.url, true).query;
    console.log(callbackObj.callback);

    //返回数据字符串,把真正数据转换成字符串拼接为函数调用
    response.write(callbackObj.callback + "(" + JSON.stringify(a) + ")");
    //发送响应
    response.end();
});
serve.listen(3000, function () {
    console.log("服务器运行在3000 端口, 请访问127.0.0.1:3000")
});


